package com.toy.controller;

import com.toy.service.FileService;
import com.toy.vo.ImageVO;
import com.toy.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author tystart
 * @create 2022-09-08-17:35
 */
@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public SysResult upload(MultipartFile file) throws IOException {
        ImageVO imageVO = fileService.upload(file);
        if (imageVO == null){
            return SysResult.fail();
        }
        return SysResult.success(imageVO);
    }

    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.removeFile(virtualPath);
        return SysResult.success();
    }

}
